<template>
  <el-menu default-active="2" :collapse="collapsed" collapse-transition router unique-opened
    class="el-menu-vertical-demo" background-color="#334157" text-color="#fff" active-text-color="#ffd04b">
    <div class="logobox">
      <img class="logoimg" src="@/assets/img/logo.png" alt="">
    </div>
    <el-submenu v-for="menu in allmenu" :key="menu.menuId" :index="menu.menuName">
      <template slot="title">
        <i class="iconfont" :class="menu.menuLogo"></i>
        <span>{{menu.menuName}}</span>
      </template>
      <el-menu-item-group>
        <el-menu-item v-for="chmenu in menu.menus" :index="'/'+chmenu.menuUrl" :key="chmenu.menuId">
          <i class="iconfont" :class="chmenu.menuLogo"></i>
          <span>{{chmenu.menuName}}</span>
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>
<script type="text/ecmascript-6">
 import {getTree} from '@/api/menu.js'
 import qs from 'qs';
 import axios from 'axios';
  export default {
    name: 'left',
    data() {
      return {
        user:{},
        collapsed: false,
        allmenu: []
      }
    },
    // 创建完毕状态(里面是操作)
    mounted() {
      // 获取图形验证码->[从后端获得该用户对应的角色进而得到用户能操作的menu]    
    let res1 = {
        code: 200,
        data: [{
            menuId: 1,
            menuLogo: 'li-icon-xitongguanli',
            menuName: '系统管理',
            menuUrl: null,
            menus: [{
                menuId: 72,
                menuLogo: 'icon-cus-manage',
                menuName: '学生管理',
                menuUrl: 'manager/student',
                menus: null
              },
              {
                menuId: 174,
                menuLogo: 'icon-cms-manage',
                menuName: '班级管理',
                menuUrl: 'manager/class',
                menus: null
              },
              {
                menuId: 73,
                menuLogo: 'icon-news-manage',
                menuName: '教师管理',
                menuUrl: 'manager/teacher',
                menus: null
              },
              
            ]
          },
          {
            menuId: 2,
            menuLogo: 'li-icon-xiangmuguanli',
            menuName: '其他',
            menuUrl: null,
            menus: [{
                menuId: 72,
                menuLogo: 'icon-cus-manage',
                menuName: '账号管理',
                menuUrl: null,
                menus: null
              },
             
            ]
          },
        ],
        msg: 'success'
      }
      //学生
      let res2 = {
        code: 200,
        data: [{
            menuId: 1,
            menuLogo: 'li-icon-xitongguanli',
            menuName: '课程安排',
            menuUrl: "null",
            menus: [{
                menuId: 72,
                menuLogo: 'icon-cus-manage',
                menuName: '课程',
                menuUrl: 'student/course',
                menus: null
              }]
          },
          {
            menuId: 2,
            menuLogo: 'li-icon-xiangmuguanli',
            menuName: '其他',
            menuUrl: null,
            menus:  [{
                menuId: 72,
                menuLogo: 'icon-cus-manage',
                menuName: '账号管理',
                menuUrl: null,
                menus: null
              },
             
            ]
          }
        ],
        msg: 'success'
      }
      //教师菜单
      let res3 = {
        code: 200,
        data: [{
            menuId: 1,
            menuLogo: 'li-icon-xitongguanli',
            menuName: "课程安排",
            menuUrl: null,
            menus:[{
                menuId: 2,
                menuLogo: 'icon-cus-manage',
                menuName: '排课',
                menuUrl: 'teacher/course',
                menus: null
              }]
            },
             {
            menuId: 2,
            menuLogo: 'li-icon-xiangmuguanli',
            menuName: '其他',
            menuUrl: null,
            menus:  [{
                menuId: 72,
                menuLogo: 'icon-cus-manage',
                menuName: '账号管理',
                menuUrl: null,
                menus: null
              },
             
            ]
          },],
        msg: 'success'
      }



      this.user = JSON.parse(localStorage.getItem('token_key'))
      if(this.user.type == 'manager'){
          this.allmenu = res1.data
      }else if(this.user.type == 'student'){  
          this.allmenu = res2.data
      }else if(this.user.type == 'teacher'){
          this.allmenu = res3.data
      }
     

    /*
    getTree({"roleId":this.user.roleId}).then(res=>{
        this.allmenu = res.data 
    })
    */

      // 监听
      this.$root.Bus.$on('toggle', value => {
        this.collapsed = !value
      })
    }
  }
</script>
<style scoped>
  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 240px;
    min-height: 400px;
  }

  .el-menu-vertical-demo:not(.el-menu--collapse) {
    border: none;
    text-align: left;
  }

  .el-menu-item-group__title {
    padding: 0px;
  }

  .el-menu-bg {
    background-color: #1f2d3d !important;
  }

  .el-menu {
    border: none;
  }

  .logobox {
    height: 40px;
    line-height: 40px;
    color: #9d9d9d;
    font-size: 20px;
    text-align: center;
    padding: 20px 0px;
  }

  .logoimg {
    height: 40px;
  }

</style>
